Move iso8859_1_to_utf8 into common code.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Thu, 30 Jun 2005 18:39:54 +0000 (18:39 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Thu, 30 Jun 2005 18:39:54 +0000 (18:39 +0000)
gpsbabel/bcr.c
gpsbabel/defs.h
gpsbabel/util.c

index 06ba79cfbae5098c2c8046fb5cb756bf71229dd7..0ef698e8125615f79c2994ccfe2df50341e6006d 100644 (file)
@@ -124,44 +124,6 @@ bcr_find_waypt(const char *name, route_head *route)                /* find a waypt by name, cr
        return wpt;
 }
 
-#ifndef UTF8_SUPPORT
-char *
-bcr_iso8859_1_to_utf8(const char *s)
-{
-       int len;
-       char *res;
-       unsigned char c;
-       char *src, *dst;
-
-       if (s == NULL) return NULL;
-
-       len = 0;
-       src = (char *)s;
-       while ('\0' != (c = *src++))
-       {
-           len++;
-           if (c & 0x80) len++;
-       }
-
-       src = (char *)s;
-       dst = res = (void *) xmalloc(len + 1);
-       while ('\0' != (c = *src++))
-       {
-           if (c & 0x80)
-           {
-               *dst++ = (0xc0 | (c >> 6));
-               *dst++ = (c & 0xbf);
-           }
-           else
-           {
-               *dst++ = c;
-           }
-       }
-       *dst = '\0';
-       return res;
-}
-#endif
-
 void
 bcr_create_waypts_from_route(route_head *route)
 {
@@ -281,11 +243,7 @@ bcr_data_read(void)
            }
            if (src != NULL) xfree(src);
            
-#ifdef UTF8_SUPPORT
            src = str_iso8859_1_to_utf8(buff);
-#else
-           src = bcr_iso8859_1_to_utf8(buff);  /* internal copy str_iso8859_1_to_utf8 */
-#endif
            /* !! buff is now free and can be used */
            
            c = bcr_next_char(src);             /* skip spaces */
index 96ef6a61f4c6ef85c46b23e43b56e9dc8a7495dc..72c5ce53aa507e3a7c408c254a1b4936eacf3d6a 100644 (file)
@@ -564,8 +564,14 @@ char * xml_entitize(const char * str);
 char * html_entitize(const char * str);
 char * strip_html(const utf_string*);
 char * strip_nastyhtml(const char * in);
-char * str_utf8_to_cp1252( const char * str );
-char * str_utf8_to_ascii( const char * str );
+
+/* 
+ * Character encoding transformations.
+ */
+char * str_utf8_to_cp1252(const char * str);
+char * str_utf8_to_ascii(const char * str);
+char * str_iso8859_1_to_utf8(const char *str );
+
 
 /* this lives in gpx.c */
 time_t xml_parse_time( const char *cdatastr );
index cb9a689df10d75c546fad3d29cf5e4aa75f851d0..654eeefbc6dd6c0c5b7e37f8befa7233cb9abb8e 100644 (file)
@@ -952,6 +952,48 @@ char * str_utf8_to_ascii( const char * str )
        return result;
 }
 
+/*
+ * str_iso8859_1_to_utf8
+ *
+ * converts the single byte charset ISO8859-1 (latin1) to UTF-8
+ */
+
+char *
+str_iso8859_1_to_utf8(const char *s)
+{
+       int len;
+       char *res;
+       unsigned char c;
+       char *src, *dst;
+
+       if (s == NULL) return NULL;
+
+       len = 0;
+       src = (char *)s;
+       while ('\0' != (c = *src++))
+       {
+           len++;
+           if (c & 0x80) len++;
+       }
+
+       src = (char *)s;
+       dst = res = (void *) xmalloc(len + 1);
+       while ('\0' != (c = *src++))
+       {
+           if (c & 0x80)
+           {
+               *dst++ = (0xc0 | (c >> 6));
+               *dst++ = (c & 0xbf);
+           }
+           else
+           {
+               *dst++ = c;
+           }
+       }
+       *dst = '\0';
+       return res;
+}
+
 /* 
  * Get rid of potentially nasty HTML that would influence another record
  * that includes;